import { App } from "vue";
import { setupTailwindcss } from "./tailwindcss";
import _ from "lodash";
/*
 * @Author: TJN tjn@246@126.com
 * @Date: 2024-07-16 15:02:33
 * @LastEditors: TJN tjn@246@126.com
 * @LastEditTime: 2024-07-26 14:48:19
 * @FilePath: \router\src\plugins\index.ts
 * @Description:
 *
 * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
 */
export function setupPlugins(app: App) {
  // 自动注册全局组件
  autoReigsterComponent(app);

  // 配置tailwindcss
  setupTailwindcss();
}

// 自动注册全局组件
function autoReigsterComponent(app: App) {
  const components = import.meta.glob("../components/form/*.vue", {
    eager: true,
  }) as Record<string, any>;
  console.log(components);
  Object.keys(components).forEach((key) => {
    const name = key.split("/").pop()?.split(".").shift() as string;

    // _.camelCase(name)  将name转换为驼峰命名的方式  比如 loginInput
    app.component(_.camelCase(name), components[key].default);
  });
}
